package cn.huangyunxing.api.service.impl.inner;

import cn.huangyunxing.api.common.ErrorCode;
import cn.huangyunxing.api.exception.BusinessException;
import cn.huangyunxing.api.mapper.InterfaceInfoMapper;
import cn.huangyunxing.common.model.entity.InterfaceInfo;
import cn.huangyunxing.common.service.InnerInterfaceInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @author : HuangXing
 * @date : 2023/9/11 19:33
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    /**
     * 根据请求路径和方法名获取接口
     * @param url
     * @param method
     * @return
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {// path -> url
        if (StringUtils.isAnyBlank(url,method)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url",url)
                .eq("method",method);
        return interfaceInfoMapper.selectOne(queryWrapper);
    }
}
